//
//  HomeSaoSaoTwoViewController.m
//  shopping
//
//  Created by 马田成 on 2017/9/30.
//  Copyright © 2017年 qianyi. All rights reserved.
//

#import "HomeSaoSaoTwoViewController.h"
#import "zhiFuMMView.h"
@interface HomeSaoSaoTwoViewController (){


     UIView *grayView;
}
@property (weak, nonatomic) IBOutlet UIImageView *headImg;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UITextField *moneyTF;
@property (nonatomic, strong) zhiFuMMView *zhiFuMMView;
@property (nonatomic, strong) NSMutableDictionary *dataDic;

@end

@implementation HomeSaoSaoTwoViewController
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:NO];
    [self creationData];
    
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setTitle:@"转账"];
    [self leftNavHide];
    UIButton *leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    leftBtn.frame = CGRectMake(0, 0, screenScale(20), screenScale(20));
    [leftBtn setBackgroundImage:[UIImage imageNamed:@"back_black"] forState:UIControlStateNormal];
    [leftBtn setBackgroundImage:[UIImage imageNamed:@"back_black"] forState:UIControlStateSelected];
    [leftBtn addTarget:self action:@selector(leftNavItemClick) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem *leftBarBtn = [[UIBarButtonItem alloc]initWithCustomView:leftBtn];
    self.navigationItem.leftBarButtonItem = leftBarBtn;

    // Do any additional setup after loading the view from its nib.
}
-(void)leftNavItemClick{
    
    //    [self.tabBarController setSelectedIndex:0];
    [self.navigationController popToRootViewControllerAnimated:YES];
}
- (IBAction)sureClick:(UIButton *)sender {
    
    grayView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, DEF_SCREEN_WIDTH, DEF_SCREEN_HEIGHT)];
    grayView.backgroundColor = [UIColor colorWithRed:0 / 255.0f green:0 / 255.0f blue:0 / 255.0f alpha:0.2];
    
    [[UIApplication sharedApplication].keyWindow addSubview:grayView];
    
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissContactView)];
    [grayView addGestureRecognizer:tapGesture];
    _zhiFuMMView = [[NSBundle mainBundle] loadNibNamed:@"zhiFuMMView" owner:self options:nil].lastObject;
    [grayView addSubview:self.zhiFuMMView];
    self.zhiFuMMView.backgroundColor = [UIColor whiteColor];
    [self.zhiFuMMView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view).with.offset(150);
        make.height.offset(88);
        make.width.offset(220);
        make.centerX.equalTo(self.view.mas_centerX);
        
    }];
    
    
    [self.zhiFuMMView.quXiaoBtn addTarget:self action:@selector(dismissContactView) forControlEvents:UIControlEventTouchUpInside];
    
    [self.zhiFuMMView.queRenBtn addTarget:self action:@selector(zhiFuMoney) forControlEvents:UIControlEventTouchUpInside];
    

    
    
    
    
}

- (void)creationData{
    
    _dataDic = [[NSMutableDictionary alloc] init];
    
    NSMutableDictionary *productParams=[[NSMutableDictionary alloc]init];
 //   NSString *token = [PublicFunction getConfigWithKey:@"token"];
    // NSString *token = @"32728a411b83e29b9836262a72477e3e0dac";
    
    [productParams setValue:self.otherToken forKey:@"token"];
    [[MNetworkHandler sharedInstance]conURL:adminLxlpersonupdate networkType:NetWorkPOST params:productParams delegate:nil showHUD:NO successBlock:^(id returnData) {
        
        if ([[returnData objectForKey:@"status"]intValue]==1) {
            
            self.dataDic = [returnData objectForKey:@"data"];
            
            self.nameLabel.text = [self.dataDic objectForKey:@"loginName"];

            NSString *urlN=manage(AP_HOST, [self.dataDic objectForKey:@"userPhoto"]);
            [self.headImg sd_setImageWithURL:[NSURL URLWithString:urlN] placeholderImage:[UIImage imageNamed:@"geren_touxiang"]];
            
            
            
            
        }
        
        else {
            
            [PublicFunction showAlert:nil message:[returnData objectForKey:@"msg"] duration:5.0f];
            
        }
        
    } failureBlock:^(NSError *error) {
        
        NSLog(@"%@",error);
        
//        [PublicFunction showAlert:nil message:@"没有连接网络" duration:10.0f];
        
    }];
    
    
}


- (void)zhiFuMoney{
    
    NSMutableDictionary *productParams=[[NSMutableDictionary alloc]init];
    NSString *token = [PublicFunction getConfigWithKey:@"token"];
    // NSString *token = @"32728a411b83e29b9836262a72477e3e0dac";
    
    [productParams setValue:token forKey:@"sweep_token"];
    //    [productParams setValue:self.orderId forKey:@"orderId"];
    [productParams setValue:self.otherToken forKey:@"cover_sweep_token"];
    [productParams setValue:self.moneyTF.text forKey:@"money"];
    [productParams setValue:self.zhiFuMMView.zhiFuTF.text forKey:@"payPwd"];
    
    [[MNetworkHandler sharedInstance]conURL:adminpaymentTransferMoney networkType:NetWorkPOST params:productParams delegate:nil showHUD:NO successBlock:^(id returnData) {
        
        if ([[returnData objectForKey:@"code"]intValue]==1) {
            
            [PublicFunction showAlert:nil message:[returnData objectForKey:@"msg"] duration:5.0f];
            [self dismissContactView];
            [self.navigationController popViewControllerAnimated:YES];
            
        }
        
        else {
            
            [PublicFunction showAlert:nil message:[returnData objectForKey:@"msg"] duration:5.0f];
            
        }
        
    } failureBlock:^(NSError *error) {
        
        NSLog(@"%@",error);
        
//        [PublicFunction showAlert:nil message:@"没有连接网络" duration:10.0f];
//        
    }];
    
    
}

- (void)dismissContactView {
    [grayView removeFromSuperview];
}





- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
